import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:myapp/app_cache.dart';
import 'package:myapp/login/login_controller.dart';

class LoginPage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return _LoginPageState();
  }
}

class _LoginPageState extends State<LoginPage> {

  final LoginController loginController = Get.put(LoginController()); // 注册控制器
  final TextEditingController usernameController = TextEditingController(text: "test01");
  final TextEditingController passwordController = TextEditingController(text: "123456");


  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: const Text("登录")),
        body: Center(
            child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    TextField(
                      controller: usernameController,
                      decoration: const InputDecoration(hintText: "请输入用户名"),
                    ),
                    TextField(
                      controller: passwordController,
                      decoration: const InputDecoration(hintText: "请输入密码"),
                      obscureText: true, // 隐藏密码输入
                    ),
                    const SizedBox(height: 20),
                    ElevatedButton(
                        child: const Text("登录"),
                        onPressed: () {
                          loginController.login(
                              usernameController.text, passwordController.text);
                        })
                  ],
                )
            )
        )
    );
  }
}
